package cn.joytur.modules.wechat.entities;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.joytur.common.annotation.TabMapping;
import cn.joytur.common.mvc.dto.Sort;
import cn.joytur.modules.wechat.entities.WechatMember;
import cn.joytur.modules.wechat.entities.base.BaseWechatMember;

/**
 * Generated by JFinal.
 */
@SuppressWarnings("serial")
@TabMapping(tabName = "joy_wechat_member")
public class WechatMember extends BaseWechatMember<WechatMember> {
	public static final WechatMember dao = new WechatMember().dao();
	
	/**
	 * 分页查询
	 */
	public Page<WechatMember> paginate(int pageNumber, int pageSize, WechatMember query, Sort sort){
		SqlPara sqlPara = getSqlPara("wechatMember.findListPage", Kv.by("query", query));
		return paginate(pageNumber, pageSize, sqlPara);
	}
	
	/**
	 * 分页查询
	 */
	public Page<WechatMember> findWapGroupPaginate(int pageNumber, int pageSize, int level, String wechatMemberId){
		SqlPara sqlPara = getSqlPara("wechatMember.findWapGroupListPage", Kv.by("level", level).set("wechatMemberId", wechatMemberId));
		return paginate(pageNumber, pageSize, sqlPara);
	}
	
	/**
	 * 查询今日新增用户
	 * @return
	 */
	public Integer findCountByToDay(){
		SqlPara sqlPara = getSqlPara("wechatMember.findCountByToDay");
		String today = DateUtil.format(new java.util.Date(), DatePattern.NORM_DATE_PATTERN) + " 00:00:00";
		return Db.queryInt(sqlPara.getSql(), today);
	}
	
	/**
	 * 
	 * @param orderNo
	 * @return
	 */
	public WechatMember findByRechargeOrderNo(String orderNo) {
		SqlPara sqlPara = getSqlPara("wechatMember.findByRechargeOrderNo", orderNo);
		return findFirst(sqlPara);
	}
}
